/*
* @Author: dongshangtong
* @Date:   2018-10-09 18:08:43
* @Last Modified by:   dongshangtong
* @Last Modified time: 2018-10-11 14:21:59
*/


const Hapi = require('hapi');
const hapiAuthJWT2 = require('hapi-auth-jwt2');
require('env2')('./.env');
const config = require('./config');
const routesHelloHapi = require('./routes/hello-hapi');
const routesShops = require('./routes/shops');
const routesOrders = require('./routes/orders');
const routesUsers = require('./routes/users');
const pluginHapiSwagger = require('./plugins/hapi-swagger');
const pluginHapiPagination = require('./plugins/hapi-pagination');
const pluginHapiAuthJWT2 = require('./plugins/hapi-auth-jwt2');


const server  = new Hapi.Server();

server.connection({
	port:config.port,
	host:config.host,
});


const  init = async() =>{

	await server.register([

		... pluginHapiSwagger,
		pluginHapiPagination,
		hapiAuthJWT2,
		]);

	pluginHapiAuthJWT2(server);

	server.route([
		... routesHelloHapi,
		... routesShops,
		... routesOrders,
		...routesUsers,
		]);

		await server.start();
		console.log(`server running at: ${server.info.uri}`);

};

init();